﻿package plugin.union.game
{
    import cmd.*;
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.util.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import morn.core.utils.*;
    import plugin.instance.*;
    import plugin.union.*;
    import uiresource.union.*;

    public class UnionActivityGame extends UnionActivityUI implements IPage
    {
        public var weekDay:Array;
        private var dieTypeArr:Array;
        private var tweenBoss:TweenMax;
        private var tweenCj:TweenMax;
        private var tweenEms:TweenMax;
        private var timeBoss:int = 0;
        private var timeCj:int = 0;
        private var timeEms:int = 0;
        private var _intvalID:int = 0;

        public function UnionActivityGame()
        {
            this.weekDay = ["日", "一", "二", "三", "四", "五", "六"];
            this.initEvent();
            return;
        }// end function

        private function initEvent() : void
        {
            btn_boss.clickHandler = new Handler(this.doUnionBoss);
            btn_caiji.clickHandler = new Handler(this.doUnionCollection);
            btn_yabiao.clickHandler = new Handler(this.doUnionEms);
            return;
        }// end function

        private function doUnionEms() : void
        {
            var _loc_1:Object = null;
            if (btn_yabiao.label == "开启活动")
            {
                UnionSender._58openUnionEms();
            }
            else if (btn_yabiao.label == "活动未开启")
            {
                WarningManager.show(1);
            }
            else
            {
                _loc_1 = ModelProxy.getValue("data", "unionEmsState");
                if (_loc_1 == null || _loc_1.state == 0)
                {
                    WarningManager.show(144);
                    return;
                }
                UnionSender._62unionEmsJoin();
            }
            return;
        }// end function

        private function doUnionCollection() : void
        {
            PluginManager.instance.sendToServer("instance", CMDInstance.NpcInstance, {mapid:16009, type:0});
            return;
        }// end function

        private function doUnionBoss() : void
        {
            var _loc_1:* = ModelProxy.getValue("data", "isUnionBossOpen");
            if (_loc_1)
            {
                PluginManager.instance.sendToServer("instance", CMDInstance.NpcInstance, {mapid:16020, type:0});
            }
            else
            {
                UnionSender._49openUnionBoss();
            }
            return;
        }// end function

        private function doWait() : void
        {
            WarningManager.show(1);
            return;
        }// end function

        public function refresh() : void
        {
            var _loc_2:Object = null;
            var _loc_1:* = ConfigDictionary.data.gameactive;
            if (this.dieTypeArr == null)
            {
                this.dieTypeArr = [];
                for each (_loc_2 in _loc_1)
                {
                    
                    if (_loc_2.dietype > 0)
                    {
                        this.dieTypeArr[_loc_2.dietype] = _loc_2;
                    }
                }
            }
            this.checkUnionBoss();
            this.checkUnionCollection();
            this.checkUnionEms();
            return;
        }// end function

        private function checkUnionEms() : void
        {
            var _loc_4:Object = null;
            var _loc_5:int = 0;
            var _loc_6:Object = null;
            var _loc_1:* = ModelProxy.getValue("data", "unionEmsState");
            if (this.tweenEms)
            {
                this.tweenEms.kill();
                this.tweenEms = null;
            }
            if (_loc_1 == null)
            {
                _loc_1 = {state:0, num:0};
            }
            var _loc_2:Object = null;
            switch(int(_loc_1.state))
            {
                case 0:
                {
                    _loc_4 = ModelProxy.getValue("data", "unionInfo");
                    _loc_5 = UserData.getUserData("rid");
                    for each (_loc_6 in _loc_4.memberList)
                    {
                        
                        if (_loc_5 == _loc_6.rid)
                        {
                            _loc_2 = _loc_6;
                            break;
                        }
                    }
                    break;
                }
                case 1:
                {
                    this.tweenEms = TweenMax.to(btn_yabiao, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
                    btn_yabiao.label = "开始押送";
                    txt_yabiao.text = "会长已开启囚犯，点击开始，一起守护囚犯吧！\n本次活动已押送：<font color=\'#" + (2 - _loc_1.num == 0 ? ("c72514") : ("53b436")) + "\'>" + (2 - _loc_1.num) + "/2</font>\n<font color=\'#e19f21\'>参加等级：70级</font>";
                    return;
                }
                case 2:
                {
                    btn_yabiao.label = "已结束";
                    txt_yabiao.text = "本次押送已结束！\n<font color=\'#e19f21\'>参加等级：70级</font>";
                    return;
                }
                default:
                {
                    break;
                }
            }
            if (_loc_2 == null)
            {
                btn_yabiao.label = "开始押送";
                txt_yabiao.text = "活动异常，我们将尽快维护！";
                return;
            }
            var _loc_3:* = this.dieTypeArr[3];
            if (this.checkTime(_loc_3, txt_yabiao, btn_yabiao, box_unionems, 3))
            {
                if (_loc_2.title >= 10)
                {
                    btn_yabiao.label = "开启活动";
                    txt_yabiao.text = "活动开放中，会员们早已热血沸腾，开启活动，一起押送吧！\n<font color=\'#00C856\'>需要会长或副会长开启</font>\n本次活动已押送：<font color=\'#" + (2 - _loc_1.num == 0 ? ("c72514") : ("53b436")) + "\'>" + (2 - _loc_1.num) + "/2</font>";
                    this.tweenCj = TweenMax.to(btn_yabiao, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
                }
                else
                {
                    btn_yabiao.label = "开始押送";
                    txt_yabiao.text = "活动开放中，会长或副会长开启后可以进行押送！\n";
                }
            }
            else
            {
                btn_yabiao.label = "活动未开启 ";
                if (this.timeEms > 0)
                {
                    this.timerHandler();
                    if (this._intvalID == 0)
                    {
                        this._intvalID = SecondTimerUtil.instance.addSecondTask(this.timerHandler);
                    }
                }
                else if (this.timeEms < 0)
                {
                    txt_yabiao.text = txt_yabiao.text + "\n<font color=\'#00C856\'>今日活动已结束<font>\n";
                }
                else
                {
                    txt_yabiao.text = txt_yabiao.text + "\n<font color=\'#00C856\'>需要会长或副会长开启</font>";
                }
            }
            txt_yabiao.text = txt_yabiao.text + "\n<font color=\'#e19f21\'>参加等级：70级</font>";
            return;
        }// end function

        private function checkUnionCollection() : void
        {
            var _loc_1:* = this.dieTypeArr[2];
            if (this.tweenCj)
            {
                this.tweenCj.kill();
                this.tweenCj = null;
            }
            if (this.checkTime(_loc_1, txt_caiji, btn_caiji, box_unioncj, 2))
            {
                txt_caiji.text = "活动开放中，进入活动，拿起武器，斩杀敌人吧！\n";
                this.tweenCj = TweenMax.to(btn_caiji, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
            }
            else
            {
                btn_caiji.label = "活动未开启 ";
                if (this.timeCj > 0)
                {
                    this.timerHandler();
                    if (this._intvalID == 0)
                    {
                        this._intvalID = SecondTimerUtil.instance.addSecondTask(this.timerHandler);
                    }
                }
                else if (this.timeCj < 0)
                {
                    txt_caiji.text = txt_caiji.text + "\n<font color=\'#00C856\'>今日活动已结束<font>";
                }
                else
                {
                    txt_caiji.text = txt_caiji.text + "\n";
                }
            }
            txt_caiji.text = txt_caiji.text + "\n<font color=\'#e19f21\'>参加等级：70级</font>";
            return;
        }// end function

        private function checkUnionBoss() : void
        {
            var _loc_4:Object = null;
            var _loc_5:int = 0;
            var _loc_6:Object = null;
            var _loc_1:* = ModelProxy.getValue("data", "isUnionBossOpen");
            var _loc_2:Object = null;
            if (_loc_1)
            {
                btn_boss.label = "进入活动";
                txt_boss.text = "行会BOSS活动已开启，进入活动一起打BOSS吧，战友们已经热血沸腾了！\n\n<font color=\'#e19f21\'>参加等级：70级</font>";
                btn_boss.filters = null;
                if (this.tweenBoss)
                {
                    this.tweenBoss.kill();
                    this.tweenBoss = null;
                }
                this.tweenBoss = TweenMax.to(btn_boss, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
                return;
            }
            else
            {
                _loc_4 = ModelProxy.getValue("data", "unionInfo");
                _loc_5 = UserData.getUserData("rid");
                for each (_loc_6 in _loc_4.memberList)
                {
                    
                    if (_loc_5 == _loc_6.rid)
                    {
                        _loc_2 = _loc_6;
                        break;
                    }
                }
            }
            if (_loc_2 == null)
            {
                btn_boss.label = "进入活动";
                txt_boss.text = "活动异常，我们将尽快维护！";
                return;
            }
            var _loc_3:* = this.dieTypeArr[1];
            if (this.checkTime(_loc_3, txt_boss, btn_boss, box_unionBoss, 1))
            {
                btn_boss.label = "进入活动";
                txt_boss.text = "活动开放中，进入活动一起打BOSS吧，战友们已经热血沸腾了！\n\n<font color=\'#e19f21\'>参加等级：70级</font>";
                btn_boss.filters = null;
                if (this.tweenBoss)
                {
                    this.tweenBoss.kill();
                    this.tweenBoss = null;
                }
                this.tweenBoss = TweenMax.to(btn_boss, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
            }
            else
            {
                btn_boss.label = "活动未开启 ";
                if (this.timeBoss > 0)
                {
                    this.timerHandler();
                    if (this._intvalID == 0)
                    {
                        this._intvalID = SecondTimerUtil.instance.addSecondTask(this.timerHandler);
                    }
                }
                else if (this.timeBoss < 0)
                {
                    txt_boss.text = txt_boss.text + "\n<font color=\'#00C856\'>今日活动已结束<font>\n";
                }
                else
                {
                    txt_boss.text = txt_boss.text + "\n";
                }
            }
            txt_boss.text = txt_boss.text + "\n<font color=\'#e19f21\'>参加等级：70级</font>";
            return;
        }// end function

        private function timerHandler() : void
        {
            var _loc_1:* = Number(ModelProxy.getValue("data", "servertime") + getTimer()) / 1000;
            var _loc_2:int = 0;
            if (this.timeBoss > 0)
            {
                _loc_2 = this.timeBoss - _loc_1;
                this.checkTimeShow(_loc_2, txt_boss, "行会BOSS活动将在：");
            }
            else if (this.timeCj > 0)
            {
                _loc_2 = this.timeCj - _loc_1;
                this.checkTimeShow(_loc_2, txt_caiji, "行会采集活动将在：");
            }
            else if (this.timeEms > 0)
            {
                _loc_2 = this.timeEms - _loc_1;
                this.checkTimeShow(_loc_2, txt_yabiao, "行会押送活动将在：");
            }
            else if (this._intvalID > 0)
            {
                SecondTimerUtil.instance.removeTask(this._intvalID);
                this._intvalID = 0;
            }
            return;
        }// end function

        public function checkTimeShow(param1:int, param2:Label, param3:String) : void
        {
            if (param1 > 0)
            {
                param2.text = param3 + "<font color=\'#00C856\'>" + TimeDataFormatUtil.getLeftTime2(param1) + "</font>后开启\n请耐心等待\n\n<font color=\'#e19f21\'>参加等级：70级</font>";
            }
            else
            {
                SecondTimerUtil.instance.removeTask(this._intvalID);
                this._intvalID = 0;
                this.refresh();
            }
            return;
        }// end function

        public function checkTime(param1:Object, param2:Label, param3:Button, param4:Box, param5:int) : Boolean
        {
            var _loc_11:int = 0;
            var _loc_12:Array = null;
            var _loc_13:Date = null;
            var _loc_14:Number = NaN;
            var _loc_15:String = null;
            var _loc_16:Array = null;
            var _loc_17:Boolean = false;
            var _loc_18:int = 0;
            var _loc_19:Array = null;
            var _loc_20:Array = null;
            var _loc_21:Array = null;
            var _loc_22:Date = null;
            var _loc_23:Date = null;
            var _loc_24:Date = null;
            var _loc_25:Number = NaN;
            var _loc_26:int = 0;
            var _loc_6:* = param1.week;
            var _loc_7:* = int((ModelProxy.getValue("data", "servertime") + Number(getTimer())) / 1000);
            var _loc_8:Boolean = true;
            var _loc_9:String = "活动开启时间：<br>";
            if (_loc_6 != null && _loc_6 != "")
            {
                _loc_11 = ModelProxy.getValue("data", "openday");
                _loc_12 = _loc_6.split("&");
                if (int(_loc_12[0]) > _loc_11)
                {
                    _loc_8 = false;
                }
                if (int(_loc_12[0]) > 0)
                {
                    _loc_9 = _loc_9 + ("开服第" + int(_loc_12[0]) + "天开始");
                }
                if (_loc_12[1] != null && _loc_12[1] != "")
                {
                    _loc_13 = new Date();
                    _loc_13.setTime(_loc_7 * 1000);
                    _loc_14 = _loc_13.day;
                    _loc_15 = _loc_12[1];
                    _loc_16 = _loc_15.split("#");
                    _loc_17 = false;
                    _loc_9 = _loc_9 + ("每周" + _loc_15.replace(/#""#/g, "、").replace(/\d""\d/g, this.getWeek) + "：<font color=\'#00C856\'>");
                    if (_loc_16.length > 0)
                    {
                        _loc_18 = 0;
                        while (_loc_18 < _loc_16.length)
                        {
                            
                            if (int(_loc_16[_loc_18]) == _loc_14)
                            {
                                _loc_17 = true;
                                var _loc_27:* = [];
                                param4.filters = [];
                                param3.filters = _loc_27;
                                break;
                            }
                            _loc_18++;
                        }
                    }
                    if (!_loc_17)
                    {
                        _loc_8 = false;
                        ObjectUtils.gray(param3);
                        ObjectUtils.gray(param4);
                    }
                }
            }
            var _loc_10:* = param1.time;
            if (param1.time != null && _loc_10 != "")
            {
                _loc_19 = _loc_10.split("-");
                _loc_20 = (_loc_19[0] as String).split("#");
                _loc_21 = (_loc_19[1] as String).split("#");
                _loc_22 = new Date(_loc_7 * 1000);
                _loc_23 = new Date(_loc_22.fullYear, _loc_22.month, _loc_22.date, int(_loc_20[0]), int(_loc_20[1]), 0, 0);
                _loc_24 = new Date(_loc_22.fullYear, _loc_22.month, _loc_22.date, int(_loc_21[0]), int(_loc_21[1]), 0, 0);
                if (_loc_23.time > _loc_24.time)
                {
                    _loc_24.time = _loc_24.time + 86400000;
                }
                _loc_25 = _loc_24.time / 1000;
                _loc_26 = 0;
                if (_loc_8)
                {
                    if (_loc_7 < _loc_23.time / 1000)
                    {
                        _loc_8 = false;
                        _loc_26 = _loc_23.time / 1000;
                    }
                    else if (_loc_7 > _loc_24.time / 1000)
                    {
                        _loc_8 = false;
                        _loc_26 = -1;
                    }
                }
                switch(param5)
                {
                    case 1:
                    {
                        this.timeBoss = _loc_26;
                        break;
                    }
                    case 2:
                    {
                        this.timeCj = _loc_26;
                        break;
                    }
                    case 3:
                    {
                        this.timeEms = _loc_26;
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                _loc_9 = _loc_9 + (_loc_10.replace(/#""#/g, ":") + "</font>开放");
                param2.text = _loc_9;
            }
            return _loc_8;
        }// end function

        public function getWeek(param1, ... args) : String
        {
            return this.weekDay[param1];
        }// end function

        public function update(param1:int, param2:Object) : void
        {
            var _loc_3:* = ModelProxy.getValue("data", "unionEmsState");
            if (_loc_3 == null)
            {
                _loc_3 = {state:0, num:0};
            }
            switch(param1)
            {
                case CMDUnion._56UNIONBOSSOPEN:
                {
                    btn_boss.label = "进入活动";
                    txt_boss.text = "会长已开启活动，进入活动一起打BOSS吧，战友们已经热血沸腾了！\n 本次活动已押送：<font color=\'#" + (2 - _loc_3.num == 0 ? ("c72514") : ("53b436")) + "\'>" + (2 - _loc_3.num) + "/2</font>\n<font color=\'#e19f21\'>参加等级：70级</font>";
                    break;
                }
                case CMDUnion._59UNIONEMSSTATE:
                {
                    switch(int(param2.state))
                    {
                        case 0:
                        {
                            btn_yabiao.label = "开启活动";
                            txt_yabiao.text = "活动开放中，会员们早已热血沸腾，开启活动，一起押送吧！\n 本次活动已押送：<font color=\'#" + (2 - _loc_3.num == 0 ? ("c72514") : ("53b436")) + "\'>" + (2 - _loc_3.num) + "/2</font>\n<font color=\'#e19f21\'>参加等级：70级</font>";
                            break;
                        }
                        case 1:
                        {
                            btn_yabiao.label = "开始押送";
                            txt_yabiao.text = "会长已开启囚犯，点击开始，一起守护囚犯吧！\n 本次活动已押送：<font color=\'#" + (2 - _loc_3.num == 0 ? ("c72514") : ("53b436")) + "\'>" + (2 - _loc_3.num) + "/2</font>\n<font color=\'#e19f21\'>参加等级：70级</font>";
                            break;
                        }
                        case 2:
                        {
                            btn_yabiao.label = "开始押送";
                            txt_yabiao.text = "本次押送已结束！\n\n<font color=\'#e19f21\'>参加等级：70级</font>";
                            break;
                        }
                        default:
                        {
                            break;
                        }
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
